﻿Imports Capa_Datos
Public Class FrmPrincipal

    Private Sub AltaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub GestionDeUsuariosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GestionDeUsuariosToolStripMenuItem.Click


        FrmGestionUsuarios.MdiParent = Me
        FormLlama = eFormulario.principal
        FrmGestionUsuarios.Show()


    End Sub

    Private Sub FrmPrincipal_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Login.Close()
    End Sub

    Private Sub FrmPrincipal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim contexto As New Capa_Datos.ContextoBAseDataContext
        Dim modulos As New DataSet
        Dim sUsuario As String
        Dim iSector As Int32
        Dim lModulos As List(Of Capa_Datos.modulos_x_sector)

        Try
            sUsuario = Login.txt_usuario.Text
            'GestionarPedidoToolStripMenuItem
            Dim per As New clsPersonas


            lModulos = contexto.trae_modulos_x_sector(per.TraerSector(sUsuario))

            'funciono
            'lModulos = contexto.trae_modulos_usuario(sUsuario)

            'lModulos = contexto.trae_modulos_x_sector(contexto.sp_trae_sector_usuario(sUsuario, 0))
            ' iSector = contexto.sp_trae_sector_usuario(sUsuario, 1).ReturnValue.ToString
            'lModulos = contexto.trae_modulos_x_sector(2)
            deshabilitar_todo_menu()


            'For Each lista As Capa_Datos.usuario_modulos In lModulos

            '    If lista.id_modulo = 1 Then
            '        GestionarPedidoToolStripMenuItem.Enabled = True
            '    ElseIf lista.id_modulo = 2 Then
            '        ModificarPedidoToolStripMenuItem.Enabled = True
            '    ElseIf lista.id_modulo = 3 Then
            '        AnularPedidoToolStripMenuItem.Enabled = True
            '    ElseIf lista.id_modulo = 4 Then
            '        CerrarPedidoToolStripMenuItem.Enabled = True
            '    ElseIf lista.id_modulo = 5 Then
            '        ConsultarPedidoToolStripMenuItem.Enabled = True
            '    ElseIf lista.id_modulo = 6 Then
            '        GestionDeUsuariosToolStripMenuItem.Enabled = True
            '    End If


            'Next

            For Each lista As Capa_Datos.modulos_x_sector In lModulos

                If lista.id_modulo = 1 Then
                    GestionarPedidoToolStripMenuItem.Enabled = True
                ElseIf lista.id_modulo = 2 Then
                    ModificarPedidoToolStripMenuItem.Enabled = True
                ElseIf lista.id_modulo = 3 Then
                    AnularPedidoToolStripMenuItem.Enabled = True
                ElseIf lista.id_modulo = 4 Then
                    CerrarPedidoToolStripMenuItem.Enabled = True
                ElseIf lista.id_modulo = 5 Then
                    ConsultarPedidoToolStripMenuItem.Enabled = True
                ElseIf lista.id_modulo = 6 Then
                    GestionDeUsuariosToolStripMenuItem.Enabled = True
                End If


            Next


        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try

    End Sub

    Private Sub deshabilitar_todo_menu()
        GestionarPedidoToolStripMenuItem.Enabled = False
        ModificarPedidoToolStripMenuItem.Enabled = False
        AnularPedidoToolStripMenuItem.Enabled = False
        CerrarPedidoToolStripMenuItem.Enabled = False
        ConsultarPedidoToolStripMenuItem.Enabled = False
        GestionDeUsuariosToolStripMenuItem.Enabled = False
    End Sub

    Private Sub habilitar_todo_menu()
        GestionarPedidoToolStripMenuItem.Enabled = True
        ModificarPedidoToolStripMenuItem.Enabled = True
        AnularPedidoToolStripMenuItem.Enabled = True
        CerrarPedidoToolStripMenuItem.Enabled = True
        ConsultarPedidoToolStripMenuItem.Enabled = True
        GestionDeUsuariosToolStripMenuItem.Enabled = True
    End Sub
End Class
